package com.cxd.ancun.controller;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONObject;
import com.cxd.ancun.service.AncunService;
import com.cxd.base.common.exception.CxdException;
import com.cxd.base.controller.BaseController;
import com.cxd.base.util.MapUtil;
import com.cxd.base.util.ParamUtil;

/**
 * <一句话功能简述> <功能详细描述>
 * @author wtj
 * @date 2016年4月6日 下午2:44:10
 * @company CXD
 * @version [Copyright (c) 2016 V001]
 */
@Controller("AncunController")
@RequestMapping("/ancunc")
public class AncunController extends BaseController{
	private static final Logger logger = Logger.getLogger(AncunController.class);
	
	@Resource
	AncunService ancunService;
	/**
	 * 投资保存存证
	 * @author wtj
	 * @date 2016年4月6日下午3:27:21
	 * @param request
	 * @param response
	 * @param value
	 * @throws IOException
	 */
	@RequestMapping(value = "investSave", method = {RequestMethod.GET,RequestMethod.POST })
	public void investSave(HttpServletResponse response,String value)throws IOException {
		super.requestLog("investSave",value);
		JSONObject json = new JSONObject();
		try {
			Map<String,String> param = MapUtil.jsonToMapString(value);
			String ancun_operation_id = param.get("ancun_operation_id");
			ParamUtil.notNullParam("安存发送记录ID:"+ancun_operation_id);
			ancunService.saveAncunSend(ancun_operation_id);
			this.jsonMsg(json, 200, "投资保存存证成功");
		} catch(CxdException e){
			super.cxdJsonException(json, e,value);
		}catch (Exception e) {
			super.jsonException(json, e, logger);
		}
		super.responseSendMsg(response, json);
	}
	
	/**
	 * 充值保存存证
	 * @author wtj
	 * @date 2016年4月6日下午3:29:42
	 * @param request
	 * @param response
	 * @param value
	 * @throws IOException
	 */
	@RequestMapping(value = "rechargeSave", method = {RequestMethod.GET,RequestMethod.POST })
	public void rechargeSave(HttpServletResponse response,String value)throws IOException {
		super.requestLog("rechargeSave",value);
		JSONObject json = new JSONObject();
		try {
			Map<String,String> param = MapUtil.jsonToMapString(value);
			String ancun_operation_id = param.get("ancun_operation_id");
			ParamUtil.notNullParam("安存发送记录ID:"+ancun_operation_id);
			ancunService.saveAncunSend(ancun_operation_id);
			this.jsonMsg(json, 200, "充值保存存证成功");
		} catch(CxdException e){
			super.cxdJsonException(json, e,value);
		}catch (Exception e) {
			super.jsonException(json, e, logger);
		}
		super.responseSendMsg(response, json);
	}

	/**
	 * 提现保存存证
	 * @author wtj
	 * @date 2016年4月6日下午3:29:25
	 * @param request
	 * @param response
	 * @param value
	 * @throws IOException
	 */
	@RequestMapping(value = "withdrawSave", method = {RequestMethod.GET,RequestMethod.POST })
	public void withdrawSave(HttpServletResponse response,String value)throws IOException {
		super.requestLog("withdrawSave",value);
		JSONObject json = new JSONObject();
		try {
			Map<String,String> param = MapUtil.jsonToMapString(value);
			String ancun_operation_id = param.get("ancun_operation_id");
			ParamUtil.notNullParam("安存发送记录ID:"+ancun_operation_id);
			ancunService.saveAncunSend(ancun_operation_id);
			this.jsonMsg(json, 200, "提现保存存证成功");
		} catch(CxdException e){
			super.cxdJsonException(json, e,value);
		}catch (Exception e) {
			super.jsonException(json, e, logger);
		}
		super.responseSendMsg(response, json);
	}
	
	
	/**
	 * 借款保存存证
	 * @author wtj
	 * @date 2016年5月12日上午9:50:22
	 * @param response
	 * @param value
	 * @throws IOException
	 */
	@RequestMapping(value = "loanSave", method = {RequestMethod.GET,RequestMethod.POST })
	public void loanSave(HttpServletResponse response,String value)throws IOException {
		super.requestLog("loanSave",value);
		JSONObject json = new JSONObject();
		try {
			Map<String,String> param = MapUtil.jsonToMapString(value);
			String ancun_operation_id = param.get("ancun_operation_id");
			ParamUtil.notNullParam("安存发送记录ID:"+ancun_operation_id);
			ancunService.saveAncunSend(ancun_operation_id);
			this.jsonMsg(json, 200, "借款保存存证成功");
		} catch(CxdException e){
			super.cxdJsonException(json, e,value);
		}catch (Exception e) {
			super.jsonException(json, e, logger);
		}
		super.responseSendMsg(response, json);
	}
}
